package org.example.simple_factory;

/**
 * @author lyq
 * @description
 * @since 2025-03-11 12:58
 */

public class SimpleFactory {
  // 产品接口
  interface Product {
    void operation();
  }

  // 具体产品类 A
  static class ConcreteProductA implements Product {
    @Override
    public void operation() {
      System.out.println("ConcreteProductA operation");
    }
  }

  // 具体产品类 B
  static class ConcreteProductB implements Product {
    @Override
    public void operation() {
      System.out.println("ConcreteProductB operation");
    }
  }

  // 简单工厂类
    public Product createProduct(String type) {
      if ("A".equals(type)) {
        return new ConcreteProductA();
      } else if ("B".equals(type)) {
        return new ConcreteProductB();
      }
      return null;
    }

}
